package LineCode.Recruit2017.小米;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 现在有一棵合法的二叉树，
 * 树的节点都是用数字表示，
 * 现在给定这棵树上所有的父子关系，
 * 求这棵树的高度
 */
public class 树的高度 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), max = 1;
        List<XiaoMiTree> xiaoMiTrees = new ArrayList<>();
        for (int i = 0; i < n-1; i++) {
            xiaoMiTrees.add(new XiaoMiTree(sc.nextInt(), sc.nextInt()));
        }
        for (XiaoMiTree index : xiaoMiTrees) {
            int m = 1, fa = index.father;
            while (fa != -1) {
                fa = findTreeAsChild(xiaoMiTrees, fa);
                m++;
            }
            if (m > max) max = m;
        }
        System.out.println(max);

    }

    public static int findTreeAsChild(List<XiaoMiTree> xiaoMiTrees, int child) {
        for (XiaoMiTree index : xiaoMiTrees) {
            if (index.child == child)
                return index.father;
        }
        return -1;
    }
}

class XiaoMiTree {
    int father;
    int child;

    public XiaoMiTree(int father, int child) {
        this.father = father;
        this.child = child;
    }
}
